package com.bear.demo1;

import static java.lang.Thread.sleep;

/**
 * @author LiuShanshan
 * @version V1.0
 * @Description
 */
public class JoinThread {

    static int r1 = 0;
    static int r2 = 0;

    public static void main(String[] args) throws InterruptedException {
        test2();
    }

    private static void test2() throws InterruptedException {
        long start = System.currentTimeMillis();
        Thread t1 = new Thread(() -> {
            try {
                sleep(5000);
                System.out.println("执行线程1方法");
                long end = System.currentTimeMillis();
                System.out.println("总共执行时间：" + (end - start));
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            r1 = 10;
        });
        t1.start();
        t1.wait();
//        sleep(1000);
        System.out.println("主线程开始执行");
        sleep(2000);
        System.out.println("主线程等待2秒之后继续运行");
        long end = System.currentTimeMillis();
        System.out.println("花费的时间:" + (end - start));
    }
}
